/**
 * @file app\utils\trace.c
 *
 * Copyright (C) 2023
 *
 * trace.c is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author HinsShum hinsshum@qq.com
 *
 * @encoding utf-8
 */

/*---------- includes ----------*/
#include "trace.h"
#include "wdt.h"
#include "resources.h"
#include "soft_timer.h"
#include "options.h"

/*---------- macro ----------*/
#define TAG "Trace"

/*---------- type define ----------*/
/*---------- variable prototype ----------*/
/*---------- function prototype ----------*/
/*---------- variable ----------*/
/*---------- function ----------*/
static void _timer_expired(timer_handle_t timer)
{
  device_ioctl(resources_get("dev_wdt"), IOCTL_WDT_FEED, NULL);
//  xlog_tag_info(TAG, "Heap    %-10s%-10s\n", "Curr", "Mini");
//  xlog_tag_info(TAG, "%-8s%-10d%-10d\n", "",
//                heap_get_free_remaining_size(),
//                heap_get_minimum_free_remaining_size());
}

void trace_init(void)
{
  timer_handle_t timer = NULL;

  timer = soft_timer_create(TAG, SFTIM_MODE_REPEAT,
                            __ms2ticks(5000), NULL, _timer_expired);
  assert(timer);
  soft_timer_start(timer);
}
